<template>
  <div id="plan-import">
  <div class="assessment-container">
    <div class="search-container">
      <div class="search-container-left" style="
    display: flex;
    align-items: center;
">
        <div class="search-container-item">
          <span>学期：</span>
          <el-select
            v-model="xq"
            style="width: 90px"
            size="mini"
            placeholder="请选择"
            @change="queryCommonNj"
          >
            <el-option
              v-for="item in xqList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div
          class="search-container-item"
          style="display: flex; flex-direction: row; justify-content: center;"
        >
          <span>年级：</span>
          <el-checkbox-group v-model="checkedYear">
            <el-checkbox v-for="year in checkedYears" :label="year.name" :key="year.id">
              {{ year.name }}
            </el-checkbox>
          </el-checkbox-group>
        </div>
        <div class="search-button" @click="queryInfo">
          <img src="../../../../assets/assessment/icon-search.png" alt="" />
          <span>查询</span>
        </div>
      </div>
    </div>
  </div>

  <div class="assessment-container">
      <div class="table-container">
        <el-table
        :data="tableData"
        border
        style="width: 100%;height:calc(100vh - 380px);overflow-y: auto;"
        class="table-data"
        row-class-name="row-class"
        cell-class-name="cell-class"
        header-row-class-name="header-row-class"
        header-cell-class-name="header-cell-class"
        @selection-change="handleSelectionChange"
        :row-key="getRowKeys"
      >
        <el-table-column width="80" align="center" :reserve-selection="true" type="selection">
        </el-table-column>
        <el-table-column
          prop="pyLevel"
          label="培养层次"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="specialtyName"
          label="专业"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="year" label="年级" align="center">
        </el-table-column>
      </el-table>
      </div>
    </div>
    <div class="wrapper-container">
      <div class="bottom-block" style="display: block">
        <div class="text">当前共找到{{ total }}条记录,当前显示{{ startPage }}-{{ endPage }}条</div>
      </div>
      <div class="pagination-block">
        <el-pagination
          prev-text="上一页"
          next-text="下一页"
          :page-size="pageSize"
          layout="prev, pager, next, jumper"
          :total="total"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
        >
        </el-pagination>
      </div>
    </div>
    <div style="margin-top: 30px;text-align: center;">
      <el-button type="warning" plain size="mini" @click="nextStep" style="margin-right:150px">下一步</el-button>
      <el-button type="danger" plain size="mini" @click="cancelStep">取 消</el-button>
    </div>
  </div>
</template>

<script>
import ButtonItem from "@/components/ButtonItem.vue";
import { querypyfaByNj, queryCommonXueqi, queryCommonNj } from "@/api/trainingManagement/place.js";
export default {
  components: { ButtonItem },
  data() {
    return {
      checkedYear: [],
      xq: "",
      xqList: [],
      tableData: [],
      multipleSelection: [],
      checkedYears: [],
      zyId:[],
      total: 0, //总条数
      pageSize: 50, //条数
      startPage: 0, //开始条数
      endPage: 0, //结束条数
      currentPage: 1, //当前页数
    };
  },
  mounted() {
    this.zyId = this.$route.query.zyId;
    this.xq = this.$route.query.xueqi;
    this.queryCommonXueqi();
  },
  methods: {
    getRowKeys(row) {
      return row.specialtyId
    },
    // 获取年级列表
    async queryCommonNj() {
      var xueqi = this.xq;
      const res = await queryCommonNj(xueqi);
      if (res.data.code == 200) {
        this.checkedYears = []
        res.data.data.forEach((item, index)=>{
          this.checkedYears.push(
            item
          )
        })
        // this.checkedYears = res.data.data;
      }
    },
    // 获取学期列表
    async queryCommonXueqi() {
      const res = await queryCommonXueqi();
      if (res.data.code == 200) {
        this.xqList = res.data.data;
        if (this.xq == "" || this.xq == null) {
          this.xq = this.xqList[0].id;
        }
        this.queryCommonNj();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.queryInfo();
    },
    // 查询
    async queryInfo() {
      if (this.checkedYear.length > 0) {
        var current = this.currentPage;
        var size = this.pageSize;
        var param = {
          nj: this.checkedYear,
        }
        const res = await querypyfaByNj(param, current, size);
        if (res.data.code == 200) {
          this.tableData = res.data.data.records;
          this.total = res.data.data.total;
          var length = this.tableData.length;
          this.calculatePage(
            this.pageSize,
            res.data.data.current, length);
        }
      } else {
        this.$message.warning("请先选择年级！");
        return
      }
    },
    // 计算开始和结束条数
    calculatePage(pageSize, current, length) {
      if (current == 1) {
        if (length != 0) {
          this.startPage = 1;
          this.endPage = length;
        }
      } else {
        this.startPage = pageSize * (current - 1) + 1;
        this.endPage = parseInt(this.startPage)  + parseInt(length) - 1;
      }
    },
    // 取消
    cancelStep() {
      this.$router.push({
        path: "/admin/teachingTaskManage/termExecutionPlan",
      });
    },
    nextStep() {
      if (this.multipleSelection.length > 0) {
        var newArr = [];
        this.multipleSelection.forEach(item => {
          var par = {
              "pyLevel": item.pyLevel,
              "year": item.year,
              "specialtyId": item.specialtyId,
              "xueqi": this.xq
          }
          newArr.push(par)
        })
        this.$router.push({
          path: "/admin/teachingTaskManage/planImportConfirm",
          query: {
            pykcList: newArr
          }
        });
      } else {
        this.$message.warning("请先选择方案数据!");
        return
      }
    },
  },
};
</script>

<style lang="less" scoped>
// 表格底部样式
@import "../../../../styles/delayedExam.less";
@import "../../../../styles/text.less";
@import "../../../../styles/supervision.less";

.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}


/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}
.assessment-container {
  width: calc(100% - 20px);
  .table-container {
     width: 100%;
  }
}
.bottom-block{
  width: calc(100% - 20px);
  margin: 0 auto;
}
</style>


<style lang="less" scoped>
  #plan-import{
    /deep/ .el-button--warning.is-plain{
      background: #FFF6EF;
      border-color: #F3B815;
      color: #F3B815;
      border-radius: 6px;
    }
    /deep/ .el-button--warning.is-plain:focus, .el-button--warning.is-plain:hover{
      color: #F3B815;
      background: #FFF6EF;
      border: 1px solid #F3B815;
      border-radius: 6px;
    }

    /deep/ .el-button--danger.is-plain{
      background: #FFEFEF;
      border-color: #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }

    /deep/ .el-button--danger.is-plain:hover{
      background: #FFEFEF;
      border: 1px solid #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }
  }
</style>
